// JavaEEPlatform by School of Informatics Xiamen University, GPL-3.0 license
package cn.edu.xmu.javaee.chapter2.beanlifecycle.config;

import cn.edu.xmu.javaee.chapter2.beanlifecycle.bean.PayAdaptor;
import cn.edu.xmu.javaee.chapter2.beanlifecycle.bean.PaymentService;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

@Configuration
public class BeanLifeCycleConfig {

    @Bean(initMethod = "myPostConstruct", destroyMethod = "myPreDestory")
    public PaymentService paymentService(PayAdaptor aliPayAdaptor, ApplicationConfig config, MessageSource messageSource) {
        return new PaymentService(messageSource, aliPayAdaptor, config);
    }

    //@Bean
    public ReloadableResourceBundleMessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:i18n/messages");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }
}
